#! /bin/bash -e

if [ "$#" -eq 0 ]; then
    echo "Usage: advanced-py-prof <python exec and arguments>"
    exit 0
fi

# Requires graphviz and gprof2dot

DATE_STAMP=$(date "+%Y-%m-%d_%H%M%S")
FILE_BASENAME=$(basename $1).${DATE_STAMP}
python -m cProfile -o ${FILE_BASENAME}.prof "$@"
gprof2dot -f pstats ${FILE_BASENAME}.prof -o ${FILE_BASENAME}.dot || { echo "This tool requires gprof2dot"; exit 1; }
dot -Teps ${FILE_BASENAME}.dot -o ${FILE_BASENAME}.eps || { echo "This tool requires graphviz (dot)"; exit 1; }
